<template>
  <div class="userManagement-container">
    <vab-query-form>
      <vab-query-form-right-panel :span="24">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.name"
              placeholder="请输入视频名"
              clearable
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      @selection-change="setSelectRows"
    >
      <el-table-column
        show-overflow-tooltip
        prop="textName"
        label="文本名称"
      ></el-table-column>
      <el-table-column show-overflow-tooltip prop="" label="源音频">
        <el-button type="text">试听</el-button>
      </el-table-column>
      <el-table-column show-overflow-tooltip prop="" label="源视频">
        <el-button type="text">试播</el-button>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="videoName"
        label="视频名称"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="editTimes"
        label="修改次数"
      ></el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNo"
      :page-size="queryForm.pageSize"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
    <edit ref="edit" @fetch-data="fetchData"></edit>
  </div>
</template>

<script>
  import { doDelete, doCut } from '@/api/videos'
  import Edit from './components/UserManagementEdit'
  export default {
    name: 'TextAudit',
    components: { Edit },
    data() {
      return {
        list: [
          {
            id: '1',
            editTimes: '123',
            textName: '1',
            videoName: '1',
            extention: '1',
          },
          {
            id: '2',
            editTimes: '123',
            textName: '2',
            videoName: '1',
            extention: '1',
          },
          {
            id: '3',
            editTimes: '123',
            textName: '3',
            videoName: '1',
            extention: '1',
          },
        ],
        cuttime: '',
        cutDialog: false,
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        elementLoadingText: '正在加载...',
        queryForm: {
          name: '',
          pageNo: 1,
          pageSize: 10,
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      handleCut() {
        if (this.selectRows.length) {
          this.cutDialog = true
          const ids_join = this.selectRows.map((item) => item.id).join()
          let paykey = {
            ids: [],
            duration: 0,
          }
          paykey.ids.push(ids_join)
          paykey.duration = Number(this.cuttime)
          this.$baseConfirm('你确定要切分选中项吗', null, async () => {
            const { msg } = await doCut(paykey)
            this.$baseMessage(msg, 'success')
          })
        } else {
          this.$baseMessage('未选中任何行', 'error')
          return false
        }
      },
      handleDelete() {
        if (this.selectRows.length) {
          const ids_join = this.selectRows.map((item) => item.id).join()
          let paykey = {
            ids: [],
          }
          paykey.ids.push(ids_join)
          this.$baseConfirm('你确定要删除选中项吗', null, async () => {
            const { msg } = await doDelete(paykey)
            this.$baseMessage(msg, 'success')
            await this.fetchData()
          })
        } else {
          this.$baseMessage('未选中任何行', 'error')
          return false
        }
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      queryData() {
        this.fetchData()
      },
      async fetchData() {
        // this.listLoading = true
        // const query = await getList(this.queryForm)
        // let data = query.data
        // this.list = data.data
        // this.total = data.totaResults
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      },
    },
  }
</script>
